package com.minggo.charmword.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.minggo.charmword.R;
import com.minggo.charmword.activity.LearnActivity;
import com.touchmenotapps.widget.radialmenu.progress.widget.RadialProgressWidget;
import com.touchmenotapps.widget.radialmenu.progress.widget.RadialProgressWidget.OnRadialViewValueChanged;

/**
 * 甩色子
 * 
 * @author minggo
 * @time 2014-6-16 S下午9:18:35
 */
public class FragmentReview extends BaseFragment implements OnClickListener {

	private Activity activity;
	private RadialProgressWidget radialProgress;
	private View mainView;

	private Button reviewBt;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.activity = activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		mainView = inflater.inflate(R.layout.fragment_review, null);

		radialProgress = (RadialProgressWidget) mainView.findViewById(R.id.radial_view);
		radialProgress.setBaseColor(activity.getResources().getColor(R.color.all_bg));
		radialProgress.setSecondaryText("完成百分比");
		radialProgress.setBorderStrokeThickness(1.2f);
		radialProgress.setBorderColor(activity.getResources().getColor(R.color.navi_index));
		radialProgress.setSecondaryTextColor(activity.getResources().getColor(R.color.prograss_text));
		radialProgress.setCenterTextColor(activity.getResources().getColor(R.color.prograss_text));
		radialProgress.setScoreColorRange(new int[] { activity.getResources().getColor(R.color.prograss) });
		// Use this to switch between static progress view and an interactive
		// one
		// mView.setTouchEnabled(false);
		radialProgress.setOnRadialViewValueChanged(new OnRadialViewValueChanged() {
			@Override
			public void onValueChanged(int value) {
				// WindowManager.LayoutParams lp =
				// activity.getWindow().getAttributes();
				// lp.screenBrightness = value / 100.0f;
				// getWindow().setAttributes(lp);
			}
		});

		reviewBt = (Button) mainView.findViewById(R.id.bt_review);
		reviewBt.setOnClickListener(this);

		if ((int) (activity.getWindow().getAttributes().screenBrightness * 100) < 0)
			radialProgress.setCurrentValue(100);
		else
			radialProgress.setCurrentValue((int) (activity.getWindow().getAttributes().screenBrightness * 100));

		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		setContentView(mainView);
	}

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);

	}

	@Override
	public void onDetach() {
		super.onDetach();
		activity = null;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_review:
			activity.startActivity(new Intent(activity, LearnActivity.class));
			break;

		default:
			break;
		}
	}

	private Handler handler = new Handler(new Callback() {

		@Override
		public boolean handleMessage(Message msg) {

			return false;
		}
	});

	@Override
	protected void showData() {
		setContentShown(false);
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				setContentShown(true);
			}
		}, 300);
	}
}
